<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  
  <title>OpenFOAM 中的单相流湍流模型之SpalartAllmaras | Giskard&#39;s CFD Learning Tricks</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <meta name="description" content="本篇简要分析不可压缩的 SpalartAllmaras 模型的代码。主要内容包括模型输运方程的代码说明，以及一些使用方面的细节。">
<meta property="og:type" content="article">
<meta property="og:title" content="OpenFOAM 中的单相流湍流模型之SpalartAllmaras">
<meta property="og:url" content="http://xiaopingqiu.github.io/2016/03/06/OpenFOAM-singlePhase-turbulenceModel2/index.html">
<meta property="og:site_name" content="Giskard's CFD Learning Tricks">
<meta property="og:description" content="本篇简要分析不可压缩的 SpalartAllmaras 模型的代码。主要内容包括模型输运方程的代码说明，以及一些使用方面的细节。">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="OpenFOAM 中的单相流湍流模型之SpalartAllmaras">
<meta name="twitter:description" content="本篇简要分析不可压缩的 SpalartAllmaras 模型的代码。主要内容包括模型输运方程的代码说明，以及一些使用方面的细节。">
  
  
    <link rel="icon" href="/favicon.png">
  
  <link href="//fonts.googleapis.com/css?family=Source+Code+Pro" rel="stylesheet" type="text/css">
  <link rel="stylesheet" href="/css/style.css" type="text/css">
  
<!-- Google Analytics -->
<script type="text/javascript">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');

##ga('create', '[object Object]', 'auto');
ga('create', 'UA-62501686-1', 'auto');
ga('send', 'pageview');

</script>
<!-- End Google Analytics -->


</head>
<body>
  <div id="container">
    <div id="wrap">
      <header id="header">
  <div id="banner"></div>
  <div id="header-outer" class="outer">
    <div id="header-title" class="inner">
      <h1 id="logo-wrap">
        <a href="/" id="logo">Giskard&#39;s CFD Learning Tricks</a>
      </h1>
      
        <h2 id="subtitle-wrap">
          <a href="/" id="subtitle">CFD and Scientific Computing</a>
        </h2>
      
    </div>
    <div id="header-inner" class="inner">
      <nav id="main-nav">
        <a id="main-nav-toggle" class="nav-icon"></a>
        
          <a class="main-nav-link" href="/">Home</a>
        
          <a class="main-nav-link" href="/archives">Archives</a>
        
          <a class="main-nav-link" href="/atom.xml">Rss</a>
        
          <a class="main-nav-link" href="/about">About</a>
        
      </nav>
      <nav id="sub-nav">
        
        <a id="nav-search-btn" class="nav-icon" title="Search"></a>
      </nav>
      <div id="search-form-wrap">
        <form action="//google.com/search" method="get" accept-charset="UTF-8" class="search-form"><input type="search" name="q" results="0" class="search-form-input" placeholder="Search"><button type="submit" class="search-form-submit">&#xF002;</button><input type="hidden" name="q" value="site:http://xiaopingqiu.github.io"></form>
      </div>
    </div>
  </div>
</header>

      <div class="outer">
        <section id="main"><article id="post-OpenFOAM-singlePhase-turbulenceModel2" class="article article-type-post" itemscope itemprop="blogPost">
  <div class="article-meta">
    <a href="/2016/03/06/OpenFOAM-singlePhase-turbulenceModel2/" class="article-date">
  <time datetime="2016-03-06T11:13:58.000Z" itemprop="datePublished">2016-03-06</time>
</a>
    
  <div class="article-category">
    <a class="article-category-link" href="/categories/OpenFOAM/">OpenFOAM</a>
  </div>

  </div>
  <div class="article-inner">
    
    
      <header class="article-header">
        
  
    <h1 class="article-title" itemprop="name">
      OpenFOAM 中的单相流湍流模型之SpalartAllmaras
    </h1>
  

      </header>
    
    <div class="article-entry" itemprop="articleBody">
      
        <p>本篇简要分析不可压缩的 SpalartAllmaras 模型的代码。主要内容包括模型输运方程的代码说明，以及一些使用方面的细节。</p>
<a id="more"></a>
<h3 id="湍流模型代码实例">湍流模型代码实例</h3><p>这一部分分析几个 OpenFOAM 里自带的湍流模型， 并探讨修改或者添加新湍流模型的方法。</p>
<h4 id="1_SpalartAllmaras_模型">1 SpalartAllmaras 模型</h4><h5 id="1-1-_模型分析">1.1. 模型分析</h5><p>SpalartAllmaras 模型是一方程模型，它只需要求解一个输运方程。OpenFOAM 中的 SpalartAllmaras 模型是在原始论文[1] 的基础上，引入了 Ashford [2] 对这个模型的修正。下面来看这个模型在 OpenFOAM 中的实现，代码位于 <code>src/turbulenceModels/incompressible/RAS/SpalartAllmaras</code><br>首先是头文件， <code>SpalartAllmaras.H</code><br>头文件开始，声明了一个类：SpalartAllmaras<br><figure class="highlight kotlin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="class"><span class="keyword">class</span> <span class="title">SpalartAllmaras</span></span></span><br><span class="line">:</span><br><span class="line">    <span class="keyword">public</span> RASModel</span><br></pre></td></tr></table></figure></p>
<p>说明这个类是公有继承 <code>RASModel</code> 类的。<br>接下来是一些数据成员以及成员函数的声明，这里无需赘述，直接来看函数的具体定义吧。<br>函数的具体定义，在<code>SpalartAllmaras.C</code> 里（注意到 OpenFOAM 的代码几乎都是这样讲声明和定义分开，这样做的目的，是为了防止重复声明的问题，更详细的说明，见我的<a href="http://xiaopingqiu.github.io/2016/03/06/separationOfDeclarationAndDefiniton/" target="_blank" rel="external">另一篇博文</a>）。注意，湍流模型的定义，最终是为了在求解器中进行调用的，所以，先来回顾一下湍流模型贡献给求解器中动量方程中那一项：<br><figure class="highlight stylus"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">turbulence-&gt;<span class="function"><span class="title">divDevReff</span><span class="params">(U)</span></span></span><br></pre></td></tr></table></figure></p>
<p>这一项，不同求解器可能会有不同，但大致的形式是这样的。<br>很显然，这个 <code>divDevReff</code> 应该是湍流模型类的成员函数，实际也的确如此， <code>SpalartAllmaras.C</code> 有这个函数的定义：<br><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">tmp</span>&lt;<span class="tag">fvVectorMatrix</span>&gt; <span class="rule"><span class="attribute">SpalartAllmaras</span>:<span class="value">:<span class="function">divDevReff</span>(volVectorField&amp; U) const</span><br><span class="line">&#123;</span><br><span class="line">    const volScalarField <span class="function">nuEff_</span>(<span class="function">nuEff</span>())</span></span>;</span><br><span class="line"></span><br><span class="line">    <span class="tag">return</span></span><br><span class="line">    (</span><br><span class="line">      <span class="tag">-</span> <span class="rule"><span class="attribute">fvm</span>:<span class="value">:<span class="function">laplacian</span>(nuEff_, U)</span><br><span class="line">      - fvc::<span class="function">div</span>(nuEff_*<span class="function">dev</span>(<span class="function">T</span>(fvc::<span class="function">grad</span>(U))))</span><br><span class="line">    )</span></span>;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>这个函数，写成公式是如下形式<br>$$<br>-\nabla \cdot (\nu_{eff}\nabla U)-\nabla \cdot [\nu_{eff}dev(\nabla ^TU)]<br>$$<br>OpenFOAM 中的 <code>dev</code>运算符定义为 $dev(T)=T-\frac{1}{3}tr(T)I$ ， <code>tr</code> 为张量的迹，即主对角元素之和所以。对于张量 $\nabla ^TU$ ，$tr(\nabla ^TU) =\nabla \cdot U$，因此上式可以写为【注一】<br>$$<br>-\nabla \cdot (\nu_{eff}\nabla U)-\nabla \cdot [\nu_{eff}(\nabla^TU-\frac{1}{3}(\nabla \cdot U))]<br>$$<br>上述 <code>divDevReff</code> 函数中，变量 <code>nuEff_</code> d的值是函数 <code>nuEff()</code> 的返回值，但是，在 <code>SpalartAllmaras.C</code> 中却未见 <code>nuEff()</code> 函数的定义。这里就要记住了，C++ 的类继承的一个特性是派生类会从基类继承其中定义的成员函数。所以看到本类中没定义的函数时，<strong>don’t panic</strong>，往基类找就是了。翻看基类 <code>RASModel</code> 的代码，可以很容易从 <code>RASModel.C</code> 中找出来 <code>nuEff()</code> 的定义：<br><figure class="highlight cs"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">virtual</span> tmp&lt;volScalarField&gt; <span class="title">nuEff</span><span class="params">()</span> <span class="keyword">const</span>  </span><br><span class="line"></span>&#123;</span><br><span class="line">    <span class="keyword">return</span> tmp&lt;volScalarField&gt;</span><br><span class="line">    (</span><br><span class="line">        <span class="keyword">new</span> volScalarField(<span class="string">"nuEff"</span>, nut() + nu())</span><br><span class="line">    );</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p> 函数 <code>nut()</code> 的定义可以从 <code>SpalartAllmaras.H</code> 中找到，可是 <code>nu()</code> 呢？虽然从名字可以猜到它返回的是分子粘度（可见变量命名的重要性啊），可是，它的定义在哪里？ <code>RASModel.C</code> 也没有啊…<br>答案是，继续向上找，RASModel 类没有，那就去更上一层的基类，turbulenceModel。果然，在 <code>turbulenceModel.C</code> 中能找到其定义：<br><figure class="highlight aspectj"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">inline tmp&lt;volScalarField&gt; nu() <span class="keyword">const</span></span><br><span class="line">    &#123;</span><br><span class="line">        <span class="function"><span class="keyword">return</span> transportModel_.<span class="title">nu</span><span class="params">()</span></span>;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure></p>
<p> <code>transportModel_</code> 又是什么鬼？这个不是本篇博文的内容，该回到正题了，这里应该关注的是湍流粘度 <code>nut_</code> 。<br>湍流模型不可能仅仅是给求解器贡献那一项，湍流粘度应该也随着求解器的运行而更新。是这样的，求解器中的<br><figure class="highlight ocaml"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">turbulence-&gt;correct<span class="literal">()</span>;</span><br></pre></td></tr></table></figure></p>
<p>这句代码负责湍流粘度的更新。这里又涉及到一个湍流类的成员函数： <code>corretc</code>。这个函数是湍流模型类的核心，因为湍流模型输运方程的求解，湍流粘度的更新都在这个函数里面。下面来看 <code>SpalartAllmaras</code> 模型的 <code>correct</code> 函数：<br><figure class="highlight aspectj"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">void</span> SpalartAllmaras::correct()</span><br><span class="line">&#123;</span><br><span class="line">    RASModel::correct();</span><br><span class="line">    <span class="keyword">if</span> (!turbulence_)</span><br><span class="line">    &#123;</span><br><span class="line">        <span class="comment">// Re-calculate viscosity</span></span><br><span class="line">        nut_ = nuTilda_*fv1(<span class="keyword">this</span>-&gt;chi());</span><br><span class="line">        nut_.correctBoundaryConditions();</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    <span class="keyword">if</span> (mesh_.changing())</span><br><span class="line">    &#123;</span><br><span class="line">        d_.correct();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">const</span> volScalarField chi(<span class="keyword">this</span>-&gt;chi());</span><br><span class="line">    <span class="keyword">const</span> volScalarField fv1(<span class="keyword">this</span>-&gt;fv1(chi));</span><br><span class="line"></span><br><span class="line">    <span class="keyword">const</span> volScalarField Stilda</span><br><span class="line">    (</span><br><span class="line">        fv3(chi, fv1)*::sqrt(2.0)*mag(skew(fvc::grad(U_)))</span><br><span class="line">      + fv2(chi, fv1)*nuTilda_/sqr(kappa_*d_)</span><br><span class="line">    );</span><br><span class="line"></span><br><span class="line">    tmp&lt;fvScalarMatrix&gt; nuTildaEqn</span><br><span class="line">    (</span><br><span class="line">        fvm::ddt(nuTilda_)</span><br><span class="line">      + fvm::div(phi_, nuTilda_)</span><br><span class="line">      - fvm::laplacian(DnuTildaEff(), nuTilda_)</span><br><span class="line">      - Cb2_/sigmaNut_*magSqr(fvc::grad(nuTilda_))</span><br><span class="line">     ==</span><br><span class="line">        Cb1_*Stilda*nuTilda_</span><br><span class="line">      - fvm::Sp(Cw1_*fw(Stilda)*nuTilda_/sqr(d_), nuTilda_)</span><br><span class="line">    );</span><br><span class="line"></span><br><span class="line">    nuTildaEqn().relax();</span><br><span class="line">    solve(nuTildaEqn);</span><br><span class="line">    bound(nuTilda_, dimensionedScalar(<span class="string">"0"</span>, nuTilda_.dimensions(), <span class="number">0.0</span>));</span><br><span class="line">    nuTilda_.correctBoundaryConditions();</span><br><span class="line"></span><br><span class="line">    <span class="comment">// Re-calculate viscosity</span></span><br><span class="line">    nut_.internalField() = fv1*nuTilda_.internalField();</span><br><span class="line">    nut_.correctBoundaryConditions();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>先看核心的输运方程， <code>nuTildaEqn</code> ，这个部分的每一行写成公式，分别如下：<br>$$<br>\frac{\partial \tilde{\nu}}{\partial t} \\<br>\nabla \cdot (U \tilde{\nu}) \\<br>-\nabla \cdot [D_{\tilde{\nu}_{eff}} \nabla \tilde{\nu}] \\<br>-\frac{C_{b2}}{\sigma_{\nu_t}} \cdot |\nabla \tilde{\nu}|^2 \\<br>C_{b1}\cdot \tilde{S} \cdot \tilde{\nu} \\<br>-\frac{C_{w1}\cdot f_w\cdot \tilde{\nu}}{d^2} \cdot \tilde{\nu}\\<br>$$</p>
<p>最后两项都包含了需要求解的量 $\tilde{\nu}$， 但是处理方式却不一样，最后一项，其实是将原本的 $\tilde{\nu} ^2$ 项进行了线性化，并用 <code>fvm::Sp</code> 操作符进行隐式处理。而倒数第二项，则是作的显式处理。差别在于，倒数第二项仅仅是用上一步得到的 $\tilde{\nu}$ 代入，然后这一项被加到 $Ax=b$ 中的 $b$ 部分。而隐式处理则会对系数矩阵 $A$ 有贡献。<br>输运方程中涉及到的变量和函数，全部都在 <code>SpalartAllmaras</code> 类中有定义，这里就不再单独分析了，仅将涉及到的公式列出如下<br>$$<br>D_{\tilde{\nu}_{eff}}=\frac{\nu+\tilde{\nu}}{\sigma_{\nu_t}}<br>$$<br>$$<br>f_w=g\cdot \left [ \frac{1+C_{w3}^6}{g^6+C_{w3}^6} \right]^{1/6},\quad  g=r+C_{w2}\cdot(r^6-r) \\<br>r=min\left[ \frac{\tilde{\nu}}{max(\tilde{S}, SMALL)\cdot \kappa^2 d^2},10 \right]<br>$$</p>
<p>$$<br>\tilde{S}=f_{v3}\cdot\sqrt{2\Omega_{ij}:\Omega_{ij}}+\frac{f_{v2}\tilde{\nu}}{\kappa^2 d^2},\quad \Omega_{ij}=\frac{1}{2}(\nabla U -\nabla ^T U)<br>$$</p>
<p>$f_{v2}$ 和 $f_{v3}$ 有点特殊，因为涉及到了 Ashford 对原始模型的修正。根据作者的论文，修正的目的是防止 $\tilde{S}$ 出现负值。<br>如果不引入 Ashford 修正，则 $f_{v3}=1$；引入以后，则<br>$$<br>f_{v3}=\frac{(1+\chi \cdot f_{v1})}{c_{v2}}\cdot \frac{3+\frac{\chi}{c_{v2}} + (\frac{\chi}{c_{v2}})^2 }{(1+\frac{\chi}{c_{v2}})^3}<br>$$<br>对于 $f_{v2}$，如果不引入 Ashford 修正，则<br>$$<br>f_{v2}=\frac{1}{(1+\frac{\chi}{c_{v2}})^3}<br>$$<br>若引入，则<br>$$<br>f_{v2}=1-\frac{\chi}{1+\chi f_{v1}}<br>$$<br>此外，<br>$$<br>f_{v1}=\frac{\chi ^3}{\chi ^3 + c_{v1}^3}, \quad  \chi=\frac{\tilde{\nu}}{\nu}, \quad \nu_t = \tilde{\nu}<br>f_{v1}$$<br>$d$ 是与壁面的距离，有一个专门的类 <code>wallDist</code> 来计算它。<br>其他的没有提到的变量，则都是模型常数了。具体的值都在 <code>SpalartAllmaras</code> 类的构造函数中定义了，这里就不再赘述了。</p>
<h5 id="1-2-_一些细节">1.2. 一些细节</h5><ol>
<li><code>turbulence_</code> 这个变量<br><code>correct</code> 函数中，只有当 <code>turbulence_</code> 为 <code>true</code> 时，下面求解输运方程的部分代码才会执行。这个变量又是从 <code>RASModel</code> 类继承过来的，其初始化的语句为 <code>turbulence_(lookup(&quot;turbulence&quot;))</code> ，这意味着，这个变量的值是从 <code>RASProperties</code> 文件中读取的（详见文末的 <code>RASProperties</code> 示例）。</li>
<li>模型常数，除了使用默认值，还可以自己指定（注：除非很有把握，一般不要随便修改模型常数）。具体方法是，在 <code>RASProperties</code> 文件里，建立一个名为 <code>SpalartAllmarasCoeffs</code> 的 subDict，详见文末的示例。 </li>
<li><code>bound</code> 函数<br>这个函数的定义在头文件 <code>bound.H</code> 里，其功能是限制 $\tilde{\nu}$ 的最小值。不过这种限制其实没有多少物理意义，纯粹是数值技巧。其中用到了 <code>fvc::average</code> 函数（见我的<a href="http://xiaopingqiu.github.io/2015/05/17/OpenFOAMcode1/" target="_blank" rel="external">另一篇博文</a>）。</li>
<li><code>read</code> 成员函数<br>这个成员函数，初看之下似乎跟模型常数的初始化有关，实则不然。模型常数的初始化在类的构造函数部分完成， <code>coeffDict_</code> 这个变量在基类 <code>RASModel</code> 的构造函数中先用 <code>type()+Coeffs</code> (这里是 <code>SpalartAllmarasCoeffs</code> )这个 subDict 初始化了，然后，在 <code>SpalartAllmaras</code> 类的构造函数中，每一个模型常数都是先去 <code>coeffDict_</code> 中查找是否用用户自定义的值，如果没有，则用模型的默认值，并且将这个默认值添加到 <code>coeffDict_</code> 这个字典中。</li>
<li>其他成员函数<br><code>SpalartAllmaras</code> 显然不需要用到湍动能 <code>k</code> 以及湍动能耗散 <code>epsilon</code> ，但是在 <code>SpalartAllmaras.C</code> 中确有这两个函数的定义，而且返回值是0。这是因为，在基类 <code>turbulenceModel</code> 中， <code>k()</code>， <code>epsilon()</code> 函数被声明为纯虚函数，如果不在 <code>SpalartAllmaras</code> 中重新定义这两个函数，则 <code>SpalartAllmaras</code> 也将是包括纯虚函数的抽象类了。在 C++ 中，抽象类是无法建立对象的。<br><code>devReff</code>， <code>R</code> ， <code>divDevRhoReff</code> 这几个成员函数，是湍流模型提供给其他模型调用的函数，比如，在计算表面应力的 <code>forces</code> 类中就需要调用湍流模型的 <code>devReff</code> 函数。</li>
</ol>
<h5 id="附：_RASProperties_文件示例">附： RASProperties 文件示例</h5><figure class="highlight markdown"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line">/<span class="emphasis">*--------------------------------*</span>- C++ -<span class="emphasis">*----------------------------------*</span>\</span><br><span class="line">| =========                 |                                                 |</span><br><span class="line">| \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox           |</span><br><span class="line">|  \\    /   O peration     | Version:  2.3.1                                 |</span><br><span class="line">|   \\  /    A nd           | Web:      www.OpenFOAM.org                      |</span><br><span class="line">|    \\/     M anipulation  |                                                 |</span><br><span class="line">\<span class="emphasis">*---------------------------------------------------------------------------*</span>/</span><br><span class="line">FoamFile</span><br><span class="line">&#123;</span><br><span class="line"><span class="code">    version     2.0;</span></span><br><span class="line"><span class="code">    format      ascii;</span></span><br><span class="line"><span class="code">    class       dictionary;</span></span><br><span class="line"><span class="code">    location    "constant";</span></span><br><span class="line"><span class="code">    object      RASProperties;</span></span><br><span class="line">&#125;</span><br><span class="line">// <span class="bullet">* *</span> <span class="bullet">* *</span> <span class="bullet">* *</span> <span class="bullet">* *</span> <span class="bullet">* *</span> <span class="bullet">* *</span> <span class="bullet">* *</span> <span class="bullet">* *</span> <span class="bullet">* *</span> <span class="bullet">* *</span> <span class="bullet">* *</span> <span class="bullet">* *</span> <span class="bullet">* *</span> <span class="bullet">* *</span> <span class="bullet">* *</span> <span class="bullet">* *</span> <span class="bullet">* *</span> <span class="bullet">* *</span> * //</span><br><span class="line"></span><br><span class="line">RASModel        SpalartAllmaras ;</span><br><span class="line">turbulence      on; //若为 off，则湍流模型的输运方程将不会求解！</span><br><span class="line">printCoeffs     on; // 输出模型常数</span><br><span class="line"></span><br><span class="line">SpalartAllmarasCoeffs // 设置模型常数(仅为示例，具体数值不要较真)</span><br><span class="line">&#123;</span><br><span class="line"><span class="code">    Cw2       0.20;</span></span><br><span class="line"><span class="code">    Cw3       0.10;</span></span><br><span class="line">&#125;</span><br><span class="line"></span><br><span class="line">// <span class="strong">*****</span><span class="strong">*****</span><span class="strong">*****</span><span class="strong">*****</span><span class="strong">*****</span><span class="strong">*****</span><span class="strong">*****</span><span class="strong">*****</span><span class="strong">*****</span><span class="strong">*****</span><span class="strong">*****</span><span class="strong">*****</span><span class="strong">*****</span><span class="strong">*****</span><span class="emphasis">***</span> //</span><br></pre></td></tr></table></figure>
<p>【注一】：N-S 方程中，这一项应该是<br>$$<br>-\nabla \cdot (\nu_{eff}\nabla U)-\nabla \cdot [\nu_{eff}(\nabla^TU-\frac{2}{3}(\nabla \cdot U))]<br>$$<br>而且，在可压缩的湍流模型中， <code>divDevReff</code> 函数用的是 <code>dev2</code> 函数，所以其定义的形式就跟 N-S 方程一致了。但不知道为什么不可压缩的湍流模型为什么要用 <code>dev</code> 函数。虽然对于不可压缩的情形，由于 $\nabla \cdot U=0$，用 <code>dev</code> 或者 <code>dev2</code> 应该关系不大，但这种做法仍然很费解。在OpenFOAM-3.0版本中，可压和不可压用的都是 <code>dev2</code> 函数了。</p>
<h5 id="参考：">参考：</h5><p>[1] P. Spalart and S. Allmaras. “A one-equation turbulence model for aerodynamic flows”. Technical Report AIAA-92-0439. American Institute of Aeronautics and Astronautics. 1992.</p>
<p>[2] “An Unstructured Grid Generation and Adaptive Solution Technique         for High Reynolds Number Compressible Flows”, G.A. Ashford, Ph.D. thesis, University of Michigan, 1996.</p>

      
    </div>
    <footer class="article-footer">
      <a data-url="http://xiaopingqiu.github.io/2016/03/06/OpenFOAM-singlePhase-turbulenceModel2/" data-id="cj2lay36n005kkkmbl8nndiof" class="article-share-link">Share</a>
      
      
  <ul class="article-tag-list"><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/Code-Explained/">Code Explained</a></li><li class="article-tag-list-item"><a class="article-tag-list-link" href="/tags/OpenFOAM/">OpenFOAM</a></li></ul>

    </footer>
  </div>
  
    
<nav id="article-nav">
  
    <a href="/2016/03/06/separationOfDeclarationAndDefiniton/" id="article-nav-newer" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Newer</strong>
      <div class="article-nav-title">
        
          为什么要将声明和定义分离
        
      </div>
    </a>
  
  
    <a href="/2015/12/12/timeVaryingBC1/" id="article-nav-older" class="article-nav-link-wrap">
      <strong class="article-nav-caption">Older</strong>
      <div class="article-nav-title">两个简单的随时间变化的边界条件</div>
    </a>
  
</nav>

  
</article>


<section id="comments">
  <!-- 多说评论框 start -->
  <div class="ds-thread" data-thread-key="post-OpenFOAM-singlePhase-turbulenceModel2" data-title="OpenFOAM 中的单相流湍流模型之SpalartAllmaras" data-url="http://xiaopingqiu.github.io/2016/03/06/OpenFOAM-singlePhase-turbulenceModel2/"></div>
  <!-- 多说评论框 end -->
  <!-- 多说公共JS代码 start (一个网页只需插入一次) -->
  <script type="text/javascript">
  var duoshuoQuery = {short_name:"xiaopingqiu"};
	(function() {
		var ds = document.createElement('script');
		ds.type = 'text/javascript';ds.async = true;
		ds.src = (document.location.protocol == 'https:' ? 'https:' : 'http:') + '//static.duoshuo.com/embed.js';
		ds.charset = 'UTF-8';
		(document.getElementsByTagName('head')[0] 
		 || document.getElementsByTagName('body')[0]).appendChild(ds);
	})();
	</script>
  <!-- 多说公共JS代码 end -->
</section>

</section>
        
          <aside id="sidebar">
  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Categories</h3>
    <div class="widget">
      <ul class="category-list"><li class="category-list-item"><a class="category-list-link" href="/categories/C/">C++</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/DEM/">DEM</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/OpenFOAM/">OpenFOAM</a><span class="category-list-count">44</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/Paraview/">Paraview</a><span class="category-list-count">5</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/swak4Foam/">swak4Foam</a><span class="category-list-count">1</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/test/">test</a><span class="category-list-count">2</span></li><li class="category-list-item"><a class="category-list-link" href="/categories/vim/">vim</a><span class="category-list-count">1</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tags</h3>
    <div class="widget">
      <ul class="tag-list"><li class="tag-list-item"><a class="tag-list-link" href="/tags/Boundary-conditions/">Boundary conditions</a><span class="tag-list-count">6</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/C/">C++</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/CentOS/">CentOS</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Code-Explained/">Code Explained</a><span class="tag-list-count">29</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/LES/">LES</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/LIGGGHTS/">LIGGGHTS</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/ODE/">ODE</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/OpenFOAM/">OpenFOAM</a><span class="tag-list-count">20</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Postprocessing/">Postprocessing</a><span class="tag-list-count">9</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Preprocessing/">Preprocessing</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/RTS/">RTS</a><span class="tag-list-count">3</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/TIL/">TIL</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/Windows/">Windows</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/fvOptions/">fvOptions</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/groovyBC/">groovyBC</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/paraview/">paraview</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/test/">test</a><span class="tag-list-count">2</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/thermophysicalModels/">thermophysicalModels</a><span class="tag-list-count">5</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/turbulence-model/">turbulence model</a><span class="tag-list-count">7</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/vim/">vim</a><span class="tag-list-count">1</span></li><li class="tag-list-item"><a class="tag-list-link" href="/tags/wall-functions/">wall functions</a><span class="tag-list-count">4</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Tag Cloud</h3>
    <div class="widget tagcloud">
      <a href="/tags/Boundary-conditions/" style="font-size: 15.56px;">Boundary conditions</a><a href="/tags/C/" style="font-size: 11.11px;">C++</a><a href="/tags/CentOS/" style="font-size: 10px;">CentOS</a><a href="/tags/Code-Explained/" style="font-size: 20px;">Code Explained</a><a href="/tags/LES/" style="font-size: 10px;">LES</a><a href="/tags/LIGGGHTS/" style="font-size: 10px;">LIGGGHTS</a><a href="/tags/ODE/" style="font-size: 10px;">ODE</a><a href="/tags/OpenFOAM/" style="font-size: 18.89px;">OpenFOAM</a><a href="/tags/Postprocessing/" style="font-size: 17.78px;">Postprocessing</a><a href="/tags/Preprocessing/" style="font-size: 11.11px;">Preprocessing</a><a href="/tags/RTS/" style="font-size: 12.22px;">RTS</a><a href="/tags/TIL/" style="font-size: 10px;">TIL</a><a href="/tags/Windows/" style="font-size: 10px;">Windows</a><a href="/tags/fvOptions/" style="font-size: 11.11px;">fvOptions</a><a href="/tags/groovyBC/" style="font-size: 10px;">groovyBC</a><a href="/tags/paraview/" style="font-size: 10px;">paraview</a><a href="/tags/test/" style="font-size: 11.11px;">test</a><a href="/tags/thermophysicalModels/" style="font-size: 14.44px;">thermophysicalModels</a><a href="/tags/turbulence-model/" style="font-size: 16.67px;">turbulence model</a><a href="/tags/vim/" style="font-size: 10px;">vim</a><a href="/tags/wall-functions/" style="font-size: 13.33px;">wall functions</a>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Archives</h3>
    <div class="widget">
      <ul class="archive-list"><li class="archive-list-item"><a class="archive-list-link" href="/archives/2017/05/">五月 2017</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/08/">八月 2016</a><span class="archive-list-count">8</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/06/">六月 2016</a><span class="archive-list-count">5</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/05/">五月 2016</a><span class="archive-list-count">3</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/04/">四月 2016</a><span class="archive-list-count">12</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2016/03/">三月 2016</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/12/">十二月 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/11/">十一月 2015</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/10/">十月 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/09/">九月 2015</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/08/">八月 2015</a><span class="archive-list-count">1</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/06/">六月 2015</a><span class="archive-list-count">2</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/05/">五月 2015</a><span class="archive-list-count">6</span></li><li class="archive-list-item"><a class="archive-list-link" href="/archives/2015/04/">四月 2015</a><span class="archive-list-count">2</span></li></ul>
    </div>
  </div>

  
    
  <div class="widget-wrap">
    <h3 class="widget-title">Recents</h3>
    <div class="widget">
      <ul>
        
          <li>
            <a href="/2017/05/12/duoshuoAnnouncement/">多说评论系统将停止提供服务</a>
          </li>
        
          <li>
            <a href="/2016/08/27/ParaviewScritps/">Paraview 脚本一例</a>
          </li>
        
          <li>
            <a href="/2016/08/27/ParaviewCamera/">Paraview 中有关 Camera 的操作两例</a>
          </li>
        
          <li>
            <a href="/2016/08/27/ParaviewCustomFilter/">Paraview 中创建 Custom Filter</a>
          </li>
        
          <li>
            <a href="/2016/08/27/ParaviewStreamLineOnSlice/">在 Paraview 中画截面上的流线</a>
          </li>
        
      </ul>
    </div>
  </div>

  
</aside>
        
      </div>
      <footer id="footer">
  
  <div class="outer">
    <div id="footer-info" class="inner">
      &copy; 2017 Giskard Q.<br>
      Powered by <a href="http://hexo.io/" target="_blank">Hexo</a>
    </div>
  </div>
</footer>

<script src="//dn-lbstatics.qbox.me/lbservice/busuanzi/2.0/busuanzi.mini.js"/></script>

    </div>
    <nav id="mobile-nav">
  
    <a href="/" class="mobile-nav-link">Home</a>
  
    <a href="/archives" class="mobile-nav-link">Archives</a>
  
    <a href="/atom.xml" class="mobile-nav-link">Rss</a>
  
    <a href="/about" class="mobile-nav-link">About</a>
  
</nav>
    

<script src="//ajax.googleapis.com/ajax/libs/jquery/2.0.3/jquery.min.js"></script>


  <link rel="stylesheet" href="/fancybox/jquery.fancybox.css" type="text/css">
  <script src="/fancybox/jquery.fancybox.pack.js" type="text/javascript"></script>


<script src="/js/script.js" type="text/javascript"></script>

<script>
  (function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
  (i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
  m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
  })(window,document,'script','//www.google-analytics.com/analytics.js','ga');

  ga('create', 'UA-62501686-1', 'auto');
  ga('send', 'pageview');

</script>

  </div>
<!-- mathjax config similar to math.stackexchange -->

<script type="text/x-mathjax-config">
  MathJax.Hub.Config({
    tex2jax: {
      inlineMath: [ ['$','$'], ["\\(","\\)"] ],
      processEscapes: true
    }
  });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Config({
      tex2jax: {
        skipTags: ['script', 'noscript', 'style', 'textarea', 'pre', 'code']
      }
    });
</script>

<script type="text/x-mathjax-config">
    MathJax.Hub.Queue(function() {
        var all = MathJax.Hub.getAllJax(), i;
        for(i=0; i < all.length; i += 1) {
            all[i].SourceElement().parentNode.className += ' has-jax';
        }
    });
</script>

<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
</body>
</html>